package com.kds.changzhou.netty;

import com.kds.changzhou.handler.*;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

/**
 * @author 孔德嵩
 */
public class TcpClientChannelInitializer extends ChannelInitializer<SocketChannel> {


    private PackageDecoder packageDecoder;

    private PackageEncoder packageEncoder;


    private XmlDecoder xmlDecoder;


    private XmlEncoder xmlEncoder;


    private SequenceHandler sequenceHandler;


    private ConnectionStatusHandler connectionStatusHandler;


    private PeriodHandler periodHandler;

    private ResultHandler resultHandler;

    private TimeHandler timeHandler;


    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        ch.pipeline().addLast(packageDecoder)
                .addLast(packageEncoder)
                .addLast(xmlDecoder)
                .addLast(xmlEncoder).
                addLast(sequenceHandler).
                addLast(resultHandler).addLast(periodHandler).addLast(timeHandler).addLast(connectionStatusHandler);
    }


    public void setPackageDecoder(PackageDecoder packageDecoder) {
        this.packageDecoder = packageDecoder;
    }

    public void setPackageEncoder(PackageEncoder packageEncoder) {
        this.packageEncoder = packageEncoder;
    }

    public void setXmlDecoder(XmlDecoder xmlDecoder) {
        this.xmlDecoder = xmlDecoder;
    }

    public void setXmlEncoder(XmlEncoder xmlEncoder) {
        this.xmlEncoder = xmlEncoder;
    }

    public void setSequenceHandler(SequenceHandler sequenceHandler) {
        this.sequenceHandler = sequenceHandler;
    }

    public void setConnectionStatusHandler(ConnectionStatusHandler connectionStatusHandler) {
        this.connectionStatusHandler = connectionStatusHandler;
    }

    public void setResultHandler(ResultHandler resultHandler) {
        this.resultHandler = resultHandler;
    }

    public void setPeriodHandler(PeriodHandler periodHandler) {
        this.periodHandler = periodHandler;
    }

    public void setTimeHandler(TimeHandler timeHandler) {
        this.timeHandler = timeHandler;
    }
}
